# Maintainer: Bruno Pagani <archange@archlinux.org>

_pkg=pdfminer
pkgname=python-${_pkg}
pkgver=20221105
pkgrel=2
pkgdesc="Python PDF Parser"
arch=(any)
url="https://github.com/pdfminer/pdfminer.six"
license=(MIT)
depends=(python-charset-normalizer python-cryptography)
makedepends=(python-setuptools cython)
checkdepends=(python-pytest)
# Provided tarballs do not include tests
#source=(${url}/releases/download/${pkgver}/${_pkg}.six-${pkgver}.tar.gz)
source=(${url}/archive/${pkgver}/${_pkg}-${pkgver}.tar.gz)
sha256sums=('820242f661589edb1ec8e110423a7cd06d776c54d9a0efdef17d3a4e61c01fa7')

build() {
  cd ${_pkg}.six-${pkgver}
  sed -i "s|__VERSION__|${pkgver}|" pdfminer/__init__.py
  python setup.py build
}

check() {
  cd ${_pkg}.six-${pkgver}
  PYTHONPATH="${PWD}"/build/lib:"${PWD}" pytest -vv --color=yes
}

package() {
  cd ${_pkg}.six-${pkgver}
  python setup.py install --skip-build --prefix=/usr --root="${pkgdir}" --optimize=1
  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/
  # Fix ownership
  chmod a+r "${pkgdir}"$(python -c "import site; print(site.getsitepackages()[0])")/pdfminer/cmap/*
}
